﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GandAInvitaciones.Base;

namespace GandAInvitaciones
{
    public partial class GenerarCupon : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Master.TituloPagina = "Generar Cupón";
                Master.DisabledBoletin();
            }
        }

        protected void BtnGenera_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    CommonServiceReference.CommonServiceClient srv = new CommonServiceReference.CommonServiceClient();
                    CommonServiceReference.Cupon obj = new CommonServiceReference.Cupon();
                    obj.CorreoElectronico = txtCorreo.Text.Trim();
                    obj.IpMod = GetDireccionIp(Request);
                    obj = srv.GeneraCupon(obj);
                    lblCupon.Text = obj.CuponGenerado;
                    HdnCodigo.Value = obj.CuponGenerado;
                    HdnFechaVigencia.Value = obj.FechaVigencia;
                    pnlPrint.Visible = true;
                    pnlCaptura.Visible = false;
                }
                else
                {
                    Master.alert("Codigo de verificación invalido", "location.reload();");
                }
            }
            catch (Exception ex)
            {
                Master.alert(ex.Message, "location.reload();");
            }
        }
    }
}